home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
TOOLS_&_
/
BUTTONEE
/
MAIN.C
next >
Wrap
C/C++ Source or Header
|
1991-02-22
|
3KB
|
130 lines
/* Buttoneer demo source code. */
/* Used to outline the default button (usually "OK") in a dialog */
static void OutlineButton(DialogPtr dialog, short itemNo)
{ short itemType;
ControlHandle item;
Rect box;
SetPort(dialog);
GetDItem(dialog, itemNo, &itemType, (Handle *)&item, &box);
PenSize(3, 3);
InsetRect(&box, -4, -4);
FrameRoundRect(&box, 16, 16);
PenSize(1, 1);
}
static short FlipDialogCheckBox(DialogPtr dialog, short itemNo)
{ short itemType;
ControlHandle item;
Rect box;
short previousValue;
GetDItem(dialog, itemNo, &itemType, (Handle *)&item, &box);
SetCtlValue(item, !(previousValue = GetCtlValue(item)));
return previousValue;
}
/* This is a standard dialog filter function.
* It will treat RETURN and ENTER as item 1, and outline item 1 as a button.
* Additional features may be added.
*/
static pascal Boolean STDfilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
{ short i;
switch(theEvent->what)
{
case keyDown:
{ i = theEvent->message & 255;
if ((i == 3) || (i == 13)) /* Return or Enter */
{ *itemHit = 1;
return 1;
}
break;
}
/* Handling of updateEvents this way was suggested and implemented
* by Clayton Prestia.
*/
case updateEvt:
{ theEvent->what = nullEvent; /* Keep the DLOG mngr's fingers out of the pie */
BeginUpdate(theDialog);
SetPort(theDialog);
EraseRect(&theDialog->portRect);
UpdtDialog(theDialog,theDialog->visRgn);
OutlineButton(theDialog, 1);
EndUpdate(theDialog);
break;
}
}
return FALSE;
}
/* Call this to show a dialog window that has an 'OK' default.
* It will first check to see if the return or enter key has already
* been pressed, and skip the dialog. This saves time on redisplays.
*/
static short MaybeShowWindow(DialogPtr dPtr)
{ EventRecord myEvent;
short x;
if(EventAvail(everyEvent, &myEvent))
{ if(myEvent.what == keyDown)
{ x = myEvent.message & charCodeMask;
if(x == 3 || x == 13) /* Return or Enter. */
{ GetNextEvent(everyEvent, &myEvent);
return 1;
}
}
}
ShowWindow(dPtr);
SetPort(dPtr);
return 0;
}
static void TestDialog(void)
{ DialogPtr dPtr;
short i;
short done = FALSE;
dPtr = GetNewDialog(128, NULL, (WindowPtr)-1);
/* Setup Dialog Here */
/* Now make it visible and do it. */
if(MaybeShowWindow(dPtr))goto ok;
while(!done)
{ ModalDialog((ProcPtr)STDfilter, &i);
switch(i)
{ case 1: /* OK */
ok:
/* Read the dialog here */
done = TRUE;
break;
case 2: /* Cancel */
done = TRUE;
break;
case 3:
case 4:
FlipDialogCheckBox(dPtr, i);
break;
default:
break;
}
}
DisposDialog(dPtr);
}
void main(void)
{ InitGraf((Ptr)&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
TestDialog();
}